
<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">权限组管理</h3>
                    </div>
                    <!-- /.card-header -->
                    <div class="card-body">
                        <table id="example1" class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>权限组ID</th>
                                <th>权限组名称</th>
                                <th>权限组描述</th>
                                <th>
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-success">操作</button>
                                        <button type="button" class="btn btn-success dropdown-toggle dropdown-hover dropdown-icon" data-toggle="dropdown">
                                            <span class="sr-only">Toggle Dropdown</span>
                                        </button>
                                        <div class="dropdown-menu" role="menu">
                                            <a class="dropdown-item" href="<?= \lib\Tool\Tools::My()->url('role/add') ?>">新增权限组</a>
                                        </div>
                                    </div>
                                </th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($data['list'] as $k=>$v){ ?>
                                <tr>
                                    <td><?= $v['group_id'] ?></td>
                                    <td><?= $v['group_name'] ?></td>
                                    <td><?= $v['group_remark'] ?></td>
                                    <td>
                                        <button type="button" class="btn btn-info btn-flat group-id" value="<?= $v['group_id'] ?>">编辑</button>
                                        <button type="button" class="btn btn-danger btn-flat">删除</button>
                                    </td>
                                </tr>
                            <?php } ?>
                            </tbody>
                            <tfoot>
                            <tr>
                               <th>权限组ID</th>
                                <th>权限组名称</th>
                                <th>权限组描述</th>
                                <th>操作</th>
                            </tr>
                            </tfoot>
                        </table>
                    </div>
                    <!-- /.card-body -->
                </div>
                <!-- /.card -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </div>
    <!-- /.container-fluid -->
</section>
<script>
    $('.group-id').click(function () {
        $("#modal-info").modal({show:true});
        $('.form-check-input').attr("checked",false);
        $('#form-menu').attr('action','index.php?c=role&m=roleMenu&group_id='+$(this).val());
        $.get("index.php?c=role&m=roleMenu",{group_id:$(this).val()},function(result){
            $.each(result.data, function (index, item) {
                $("#menu-"+item.menu_id).attr("checked",true);
            });
        },'json');
    });
</script>
<style>
    .menu-check{
        width: 100%;
        overflow: hidden;
    }
    .menu-check li{
        list-style-type:none;
        float: left;
    }
    .menu-check .margin-menu{
        margin-left: 10px;
    }
</style>
<div class="modal fade" id="modal-info">
<div class="modal-dialog">
    <form id="form-menu" action="" method="post">
        <div class="modal-content bg-info">
        <div class="modal-header">
          <h4 class="modal-title">选择权限访问模块</h4>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
                 <?php foreach($menuData as $k=>$v){ ?>
                     <div class="form-check menu-check" >
                         <ul>
                             <li>
                                  <input class="form-check-input" name="menu_id[]" type="checkbox" id="menu-<?= $v['menu_id'] ?>" value="<?= $v['menu_id'] ?>">
                                  <label class="form-check-label"> <?= $v['menu_name'] ?></label>
                             </li>
                             <?php foreach($v['children'] as $ks=>$vs){ ?>
                             <li class="margin-menu">
                                 <input class="form-check-input"  name="menu_id[]" type="checkbox" id="menu-<?= $vs['menu_id'] ?>" value="<?= $vs['menu_id'] ?>" style="float: left;">
                                 <label class="form-check-label" style="display: block;float: left;"> <?= $vs['menu_name'] ?></label>
                             </li>
                             <?php } ?>
                         </ul>
                    </div>
                 <?php } ?>

        </div>
        <div class="modal-footer justify-content-between">
          <button type="button" class="btn btn-outline-light" data-dismiss="modal">关闭</button>
          <button type="submit" class="btn btn-primary">保存</button>
        </div>
      </div>
        <!-- /.modal-content -->
    </form>
</div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->
